//
//  StatisticsDiaryView.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/2/14.
//

import SwiftUI
//统计日历图
struct StatisticsMoodView: View {
    @EnvironmentObject var themeManager: ThemeManager
    @StateObject var viewModel = StatisticsDiaryViewModel()
    let type : IStatisticsType = IStatisticsType.MOOD
    
    var body: some View {
        GeometryReader { geometry in
            ZStack{
                if !viewModel.status.isEmpty {
                    HomeEmptyView(text1: viewModel.status)
                        .frame(maxWidth: .infinity,maxHeight: .infinity)
                } else {
                    ScrollView {
                        //需要嵌套一层LazyVStack，不然会产生间距，而且大小还会随机
                        LazyVStack(spacing: 0) {
                            ForEach(viewModel.items, id: \.id) { item in
                                CalendarMoodMonthItemView(item: item, width: geometry.size.width)
                                    .padding(.top, 15)
                                    .tag(item.id)  // 明确视图标识
                            }
                            LoadMoreFooter(refreshing: $viewModel.footerRefreshing, action: {
                                viewModel.getData(false,type)
                            }) {
                                LoadMoreView(noMore: viewModel.noMore, footerRefreshing: viewModel.footerRefreshing)
                            }
                            .noMore(viewModel.noMore)
                            .preload(offset: 10)
                        }
                    }.enableRefresh()
                        .padding(.horizontal, 20)
                        .onAppear{
                            if !viewModel.isInit {
                                viewModel.getData(true,type)
                                viewModel.isInit = true
                            }
                        }
                }
            }
        }
    }
}

//#Preview {
//    StatisticsDiaryView()
//}

//定义预览提供者
struct StatisticsDiaryView_Previews: PreviewProvider {
    static var previews: some View {
        //使用预览共享配置
        configurePreviewEnvironment(for: StatisticsDiaryView())
    }
}

